package org.smart4j.plugin.security.tag;

import org.apache.shiro.web.tags.PermissionTag;

import java.util.Arrays;
import java.util.List;

/**
 * Created by Wangminze on 2016/12/31.
 * Description: 判断当前用户是否拥有其中所有权限（逗号分隔，表示"与"的关系）
 */
public class HasAllPermissionsTag extends PermissionTag {

    private static final String PERMISSION_NAMES_DELIMITER = ",";

    @Override
    protected boolean showTagBody(String permissionNames) {

        boolean hasAnyPermission = true;

        List<String> permissionList = Arrays.asList(permissionNames.split(PERMISSION_NAMES_DELIMITER));
        if(permissionList.size() > 0){
            for (String permission : permissionList){
                if ( !isPermitted(permission) ){
                    hasAnyPermission = false;
                }
            }
        }
        return hasAnyPermission;
    }


}
